package com.yalantis.euclid.sample;

import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.Toast;

import com.google.gson.Gson;
import com.yalantis.euclid.domains.Result;
import com.yalantis.euclid.domains.Suggestion;
import com.yalantis.euclid.domains.WordInfo;
import com.yalantis.euclid.library.EuclidActivity;
import com.yalantis.euclid.library.EuclidListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Oleksii Shliama on 1/27/15.
 */
public class MainActivity extends EuclidActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mButtonProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(MainActivity.this, "Oh hi!", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected BaseAdapter getAdapter() {
        Map<String, Object> profileMap;
        int[] avatars = {
                R.drawable.dialog1,
                R.drawable.emotion1,
                R.drawable.suggestion1};
        String[] names = {"对话分析","情绪猜测","建议"};
        String[]  shortDescription = {"看一下你和TA之间所得最多的是什么","看一看TA的心情如何","给你一个小小的建议"};
        String[]  longDescription = {"","",""};
        List<Map<String, Object>> profilesList = new ArrayList<>();
        Gson gson = new Gson();
        if(!ContentString.resultJson.equals("")){
            Result result = gson.fromJson(ContentString.resultJson, Result.class);
            longDescription[0] += "这是你们对话中出现最多的词:\n";
            List<WordInfo> wordInfos = result.getWordInfo();
            for (int i = 0;i < 5;i++){
                longDescription[0] +="\t"+wordInfos.get(i).toString()+ "\n";
            }
            longDescription[1] = result.getEmotion().toString();
            for(Suggestion s:result.getSuggestions()){
                longDescription[2] += s.toString();
            }

        }

//        for (int i = 0; i < avatars.length; i++) {
//            profileMap = new HashMap<>();
//            profileMap.put(EuclidListAdapter.KEY_AVATAR, avatars[i]);
//            profileMap.put(EuclidListAdapter.KEY_NAME, names[i]);
//            profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_SHORT, getString(R.string.lorem_ipsum_short));
//            profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_FULL, getString(R.string.lorem_ipsum_long));
//            profilesList.add(profileMap);
//        }
        //对话分析
        profileMap = new HashMap<>();
        profileMap.put(EuclidListAdapter.KEY_AVATAR, avatars[0]);
        profileMap.put(EuclidListAdapter.KEY_NAME, names[0]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_SHORT, shortDescription[0]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_FULL, longDescription[0]);
        profilesList.add(profileMap);
        //情绪猜测
        profileMap = new HashMap<>();
        profileMap.put(EuclidListAdapter.KEY_AVATAR, avatars[1]);
        profileMap.put(EuclidListAdapter.KEY_NAME, names[1]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_SHORT, shortDescription[1]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_FULL, longDescription[1]);
        profilesList.add(profileMap);
        //建议
        profileMap = new HashMap<>();
        profileMap.put(EuclidListAdapter.KEY_AVATAR, avatars[2]);
        profileMap.put(EuclidListAdapter.KEY_NAME, names[2]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_SHORT, shortDescription[2]);
        profileMap.put(EuclidListAdapter.KEY_DESCRIPTION_FULL, longDescription[2]);
        profilesList.add(profileMap);



        return new EuclidListAdapter(this, R.layout.list_item, profilesList);
    }

}
